<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh">
<head>

	<jsp:include page="/commonPages/admin-meta.jsp" flush="true" />
	<!-- CSS files -->
	<jsp:include page="/commonPages/admin-style.jsp" flush="true" />
	<style type="text/css">
	.glyphicon{
		width: 20px;
		height: 20px;
		cursor: pointer;
	}
	.checkbox{
		margin-top: 10px!important;
	}
	 #map{
                position: relative;
                height: 520px;
                border:1px solid #3473b7;
            }
            #toolbar{
                position: relative;
                height: 33px;
                padding-top:5;
            }
	</style>
	<script src='./libs/SuperMap.Include.js'></script>
        <script type="text/javascript">
            //var host = document.location.toString().match(/file:\/\//)?"http://localhost:8090":'http://' + document.location.host;
            var map, local, layer, vectorLayer, drawPolygon,
            style = {
                strokeColor: "#304DBE",
                strokeWidth: 1,
                pointerEvents: "visiblePainted",
                fillColor: "#304DBE",
                fillOpacity: 0.8
            },
            url1 = "http://222.25.188.1:50118/iserver/services/map-YC/rest/maps/urban_master_plan";
   // url="http://localhost:8090/iserver/services/map-china400/rest/maps/China";
            url2="http://222.25.188.1:50118/iserver/services/data-YC/rest/data";
            function init(){
                layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url1, {transparent: true, cacheEnabled: true}, {maxResolution:"auto"});
                layer.events.on({"layerInitialized":addLayer});
                vectorLayer = new SuperMap.Layer.Vector("Vector Layer");

                drawPolygon = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Point);
                drawPolygon.events.on({"featureadded": drawCompleted});
                //给在vector图层上所选择的要素初始化
                select = new SuperMap.Control.SelectFeature(vectorLayer, {onSelect: processCompleted,repeat:true});


                map = new SuperMap.Map("map",{controls: [
                    new SuperMap.Control.LayerSwitcher(),
                    new SuperMap.Control.ScaleLine(),
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                        enableKinetic: true
                        }}),
                    drawPolygon]
                });
                map.addControl(select);
                map.events.on({"click":drawGeometry});//鼠标点击事件
            }

            function addLayer() {
                map.addLayers([layer, vectorLayer]);
                map.setCenter(new SuperMap.LonLat(37426892.09 , 4083177.09), 0);
            }
            function drawGeometry() {
                //先清除上次的显示结果
                vectorLayer.removeAllFeatures();
                drawPolygon.activate();
            }
            function drawCompleted(drawGeometryArgs) {
                var geometry = drawGeometryArgs.feature.geometry;
                vectorLayer.removeAllFeatures();
                var getFeaturesByGeometryParameters, getFeaturesByGeometryService;
                getFeaturesByGeometryParameters = new SuperMap.REST.GetFeaturesByGeometryParameters({
                    datasetNames: ["超图数据:县城城市总体规划"],
                    toIndex:-1,
                    spatialQueryMode:SuperMap.REST.SpatialQueryMode.INTERSECT,
                    geometry: drawGeometryArgs.feature.geometry,
                    returnContent:true,
                });
                getFeaturesByGeometryService = new SuperMap.REST.GetFeaturesByGeometryService(url2, {
                    eventListeners: {
                        "processCompleted": processCompleted,
                        "processFailed": processFailed
                    }
                });
                getFeaturesByGeometryService.processAsync(getFeaturesByGeometryParameters);
            }
            function processCompleted(getFeaturesEventArgs) {
                drawPolygon.deactivate();
                var i, len, features, feature, result = getFeaturesEventArgs.result;
                
                if (result && result.features) {
                    features = result.features
                    for (i=0, len=features.length; i<len; i++) {
                    	
                        feature = features[i];
                        feature.style = style;
                        vectorLayer.addFeatures(feature);
                    }
                }
             
                     resultHtml = "<div style='font-size:.20em; opacity: 0.8; overflow-y:hidden;'>"
                     				+"<table  class = 'table table-striped table-bordered table-hover' id ='list_api' >"
                     				+"<caption align = 'center'> 属性列表 </caption>"
                     				+"<tr>"
                     				+"<th > 属性名称  "+"</th>" 
                     				+"<th>    属性值        "+"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SMID "+"</th>" 
                     				+"<th> "+  feature.attributes["SMID"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SmSdriW "+"</th>" 
                     				+"<th> "+  feature.attributes["SmSdriW"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SmSdriN "+"</th>" 
                     				+"<th> "+  feature.attributes["SmSdriN"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SmSdriE "+"</th>" 
                     				+"<th> "+  feature.attributes["SmSdriE"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SmSdriS "+"</th>" 
                     				+"<th> "+  feature.attributes["SmSdriS"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SmArea "+"</th>" 
                     				+"<th> "+  feature.attributes["SmArea"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SmUserID "+"</th>" 
                     				+"<th> "+  feature.attributes["SmUserID"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SmPerimeter "+"</th>" 
                     				+"<th> "+  feature.attributes["SmPerimeter"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SmGeometrySize "+"</th>" 
                     				+"<th> "+  feature.attributes["SmGeometrySize"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > YDFL "+"</th>" 
                     				+"<th> "+  feature.attributes["YDFL"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SHAPE_LENG "+"</th>" 
                     				+"<th> "+  feature.attributes["SHAPE_LENG"] +"</th>" 
                     				+"</tr>"
                     				+"<tr>"
                     				+"<th > SHAPE_AREA "+"</th>" 
                     				+"<th> "+  feature.attributes["SHAPE_AREA"] +"</th>" 
                     				+"</tr>"
                     				+"</div>"

                 popup = new SuperMap.Popup.FramedCloud("chicken",
                            feature.geometry.getBounds().getCenterLonLat(),
                            null,
                            resultHtml,
                            null,
                            true,
                            null,
                            true);
                    popup.closeOnMove = true;
                    
                    popup.autoSize = true;
                    popup.backgroundColor = "none";
                    popup.panMapIfOutOfView = true;
                    feature.popup = popup;
                    map.addPopup(popup);

            }
            function processFailed(e) {
                alert(e.error.errorMsg);
            }
            function clearFeatures() {
                //vectorLayer.removeAllFeatures();
                feature.popup.hide();
                feature.popup.destroy();
                
            }
            
        </script>
</head>
<body onload="init()">
	   <div id="wrapper">

        <!-- Navigation -->
        <jsp:include page="/commonPages/admin-navigator.jsp" flush="true" />
        <jsp:include page="/commonPages/admin-script.jsp" flush="true" />

       </div>
       <div id="page-wrapper">
        <div id="map"  onMouseUp="clearFeatures()"></div>
        </div>
    </body> 
</html>